//
//  LGUserAccountModel.swift
//  LGWeibo
//
//  Created by 李更 on 8/11/16.
//  Copyright © 2016 itcast. All rights reserved.
//

import UIKit
//使用归档解档需要继承nscoding

class LGUserAccountModel: NSObject ,NSCoding{
    
    //用户授权的唯一票据
    var access_token  : String?
    // 过期时间
    var expires_in  : NSTimeInterval = 0{
        didSet{
            expires_Date = NSDate(timeIntervalSinceNow: expires_in)
        }
    }
    //授权用户ID
    var uid : String?
    //用户昵称
    var screen_name : String?
    //用户头像
    var avatar_large : String?
    //程序猿自己添加的属性，用于显示过期时间、
    var expires_Date : NSDate?
    
    func encodeWithCoder(aCoder: NSCoder) {
        aCoder.encodeObject(access_token, forKey: "access_token")
         aCoder.encodeObject(uid, forKey: "uid")
         aCoder.encodeObject(screen_name, forKey: "screen_name")
         aCoder.encodeObject(avatar_large, forKey: "avatar_large")
         aCoder.encodeObject(expires_Date, forKey: "expires_Date")
    }
    
    required init?(coder aDecoder: NSCoder) {
        access_token = aDecoder.decodeObjectForKey("access_token") as? String
         uid = aDecoder.decodeObjectForKey("uid") as? String
         screen_name = aDecoder.decodeObjectForKey("screen_name") as? String
         avatar_large = aDecoder.decodeObjectForKey("avatar_large") as? String
         expires_Date = aDecoder.decodeObjectForKey("expires_Date") as? NSDate
    }
    
    
    
       init(dict:[String : AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
     override var description: String{
        let keys = ["access_token","expires_Date","uid","screen_name","avatar_large"]
        return dictionaryWithValuesForKeys(keys).description
        
    }

  
}

